/**
 * @author  冯胜德
 * @comment 自定义函数
 */
define([] , function () {
	 return { 	
		 // 获取当前时间
		 getTimestamp : function() {
			 var time = new Date();
			 return time.getTime();
		},
		
		// 取doc
		doc : function(id) {
			return document.getElementById(id).innerHTML;
		},
		
		// 取UUID
		uuid : function() {
			var s = [];
			var hexDigits = "0123456789abcdef";
			for (var i = 0; i < 36; i++) {
				s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
			}
			s[14] = "4";
			s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
			s[8] = s[13] = s[18] = s[23] = "-";
			var uuid = s.join("");
			return uuid;
		},
		
		// 验证手机号码
		isMobile : function(mobile){
			var isMobile = /^(?:13\d|15\d|18\d)\d{5}(\d{3}|\*{3})$/;
			return isMobile.test(mobile);		
		},
		
		// 验证手机号码
		isEmail : function(email){
			var isEmail = /^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/;
			return　 isEmail.test(email);
		},
			
		// 获取项目根路径
		root : function() {
			var curWwwPath = window.document.location.href;
			var pathName = window.document.location.pathname;
			var pos = curWwwPath.indexOf(pathName);
			var localhostPath = curWwwPath.substring(0, pos);
			var projectName = pathName.substring(0,pathName.substr(1).indexOf('/') + 1);
			return (localhostPath + projectName);
		},
		
		//设置cookie
		setCookie :  function(name,value,time){
		    var strsec = getsec(time); 
		    var exp = new Date(); 
		    exp.setTime(exp.getTime() + strsec*1); 
		    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
		},
		
		//读取cookie
		getCookie : function(name){
		    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
		    if(arr=document.cookie.match(reg)){
		        return unescape(arr[2]); 
		    } else{
		        return null; 
		    } 
		},
		
		delCookie : function(){
		    var exp = new Date(); 
		    exp.setTime(exp.getTime() - 1); 
		    var cval=getCookie(name); 
		    if(cval!=null){
		        document.cookie= name + "="+cval+";expires="+exp.toGMTString(); 
		    }
		 },
	 };
	 
	//这是有设定过期时间的使用示例： 
	//s20是代表20秒 
	//h是指小时，如12小时则是：h12 
	//d是天数，30天则：d30 
	function getsec(str){
		var str1=str.substring(1,str.length)*1; 
		   var str2=str.substring(0,1); 
		   if (str2=="s"){ 
			   return str1*1000; 
		   }else if (str2=="h") { 
			   return str1*60*60*1000; 
		   }else if (str2=="d")
		   { 
			   return str1*24*60*60*1000; 
		   } 
		}
});
